package zozopo.business;

import java.io.IOException;

import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.interceptor.ServletResponseAware;

import zozopo.operations.business.StoreOS;
import zozopo.operations.business.StoreTB;

import com.opensymphony.xwork2.ActionSupport;

public class StoreAction extends ActionSupport implements ServletResponseAware{
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	private Integer id;
	private StoreTB store;
	private String from;
	
	HttpServletResponse response;
	
	public String execute(){
		
		StoreOS storeOS = new StoreOS();
		store = storeOS.getStoreById(id);
		storeOS.flow(id);//流览+1
		storeOS.releaseConnection();
		
		if(from != null && from.equals("REMOTE")){
			try {
				response.sendRedirect(store.getUrl_store());
				return NONE;
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			
		}
		

		return SUCCESS;
	}

	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public StoreTB getStore() {
		return store;
	}

	public void setStore(StoreTB store) {
		this.store = store;
	}

	public String getFrom() {
		return from;
	}

	public void setFrom(String from) {
		this.from = from;
	}
	
	public void setServletResponse(HttpServletResponse arg0) {
		// TODO Auto-generated method stub
		response = arg0;
		
	}
}
